package com.glory.brepda.activity.mfg;


import android.view.View;
import android.widget.LinearLayout;
import android.widget.RadioButton;
import android.widget.TextView;
import com.glory.brepda.R;
import com.glory.brepda.base.BaseActivity;
import com.glory.brepda.callback.CustomDialogEntityCallBack;
import com.glory.brepda.entity.response.BaseResponseBean;
import com.glory.brepda.utils.NetUtils;
import com.google.gson.JsonObject;
import com.google.gson.reflect.TypeToken;
import com.lzy.okgo.model.Response;
import com.pda.platform.ui.ui_pdaplatform.callback.FreeUI_EntityCallBack;
import com.pda.platform.ui.ui_pdaplatform.utils_public.FreeApi_LogUtils;
import com.pda.platform.ui.ui_pdaplatform.view.FreeUI_ClearEditText;

import butterknife.BindView;
import butterknife.OnClick;

public class LowerFrameActivity extends BaseActivity {

    @BindView(R.id.tvTitle)
    TextView tvTitle;
    @BindView(R.id.tvBaseSubmit)
    TextView tvBaseSubmit;
    @BindView(R.id.llMain)
    LinearLayout llMain;
    @BindView(R.id.etEqpID)
    FreeUI_ClearEditText etEqpID;
    @BindView(R.id.rbTrue)
    RadioButton rbTrue;
    @BindView(R.id.rbFalse)
    RadioButton rbFalse;

    @Override
    protected int getLayoutResId() {
        return R.layout.activity_lower_frame;
    }

    @Override
    protected void initView() {
        tvTitle.setText("框架一键下机");
        setMainLayout(llMain);
    }

    @Override
    protected void initData() {

    }

    @OnClick({R.id.tvBaseSubmit})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.tvBaseSubmit:
                FreeUI_EntityCallBack<BaseResponseBean<Object>> callBack = new CustomDialogEntityCallBack<BaseResponseBean<Object>>
                        (new TypeToken<BaseResponseBean<Object>>() {
                        }.getType(),getSupportFragmentManager(), this) {

                    @Override
                    public void onSuccess(Response<BaseResponseBean<Object>> response) {
                        super.onSuccess(response);
                        if (response.body().isSuccess(LowerFrameActivity.this, false, getSupportFragmentManager())) {
                            showToast("料框下机成功",true);
                            finish();
                        }
                    }

                    @Override
                    public void onError(Response<BaseResponseBean<Object>> response) {
                        super.onError(response);
                        FreeApi_LogUtils.saveErrorMessages(response.getException(), "MLOTFRAMEDEATCH");
                    }
                };
                JsonObject map = new JsonObject();
                map.addProperty("ACTIONTYPE", "DEASSIGN");
                map.addProperty("EQUIPMENTID", getText(etEqpID));
                map.addProperty("ISCOSUME", rbTrue.isChecked());
                NetUtils.requestPostNet("IF.MLOTFRAMEDEATCH", "Common", LowerFrameActivity.this, map, callBack);
                break;
        }
    }

}